import java.util.*;
import java.io.* ;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main{
    static Read in = new Read() ;
    static PrintWriter out = new PrintWriter(
            new BufferedWriter(
                    new OutputStreamWriter(System.out)
            )
    );
    public static void main(String[] args) throws IOException {
        int n = in.nextInt() ;
        int v = in.nextInt() ;
        int[] vm = new int[n+1] ;
        int[] sm = new int[n+1] ;
        int[][] dp = new int[n + 1][v + 1] ;
        for (int i = 1 ; i <= n ; i ++) {
            vm[i] = in.nextInt() ;
            sm[i] = in.nextInt() ;
        }
        for (int i = 1 ; i <= n ; i ++) {
            for (int j = 1; j <= v;  j ++) {
                dp[i][j] = dp[i-1][j] ;
                if (vm[i] <= j) {
                    dp[i][j] = Math.max(dp[i - 1][j], sm[i] + dp[i-1][j - vm[i]]);
                }
            }
        }
        out.println(dp[n][v]) ;
        dp = new int[n + 1][v + 1];
        for (int i = 1 ; i <= v ; i ++) {
            dp[0][i] = -1 ;
        }

        for (int i = 1 ; i <= n ; i++) {
            for (int j = 1 ; j <= v ; j ++) {
                dp[i][j] = dp[i-1][j] ;
                if(j >= vm[i] && dp[i-1][j-vm[i]] != -1){
                    dp[i][j] = Math.max(dp[i][j] , sm[i] + dp[i-1][j-vm[i]]) ;
                }
            }
        }
        out.println(dp[n][v]==-1?0:dp[n][v]) ;

        out.close() ;
    }
}

class Read {
    private StringTokenizer st = new StringTokenizer("");
    private BufferedReader bf = new BufferedReader(new InputStreamReader(
            System.in)) ;

    public  String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine()) ;
        }
        return st.nextToken() ;
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next()) ;
    }
}